package com.atguigu.k_synchronzied;

import java.util.concurrent.TimeUnit;

// 资源类手机
class Phone{
    public static synchronized void SendMessage(){
        try {
            TimeUnit.SECONDS.sleep(4);
            System.out.println("发送短信。。。");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public synchronized void PlayMusic(){
        System.out.println("播放音乐。。。");
    }

    public void SayHello(){
        System.out.println("sayHello...");
    }
}

public class Test {
    public static void main(String[] args) {
        Phone phone = new Phone();
        Phone phone1 = new Phone();
        new Thread(()->{
            phone.SendMessage();
        }, "p1").start();

        /*new Thread(()->{
//            phone.SayHello();
            phone.PlayMusic();
        }, "p2").start();*/

        new Thread(()->{
           phone1.PlayMusic();
        }, "p3").start();

    }
}
